package com.jn.tendemo.view;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class URLExtractor {

    /**
     * 从文本中提取所有URL
     *
     * @param text 包含URL的文本
     * @return 包含所有URL的列表
     */
    public static List<String> extractUrls(String text) {
        List<String> urls = new ArrayList<>();

        // 正则表达式，用于匹配URL
        String regex = "((https?|ftp|gopher|telnet|file):((//)|(\\\\))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(text);

        while (matcher.find()) {
            urls.add(matcher.group());
        }

        return urls;
    }
}

